/*
	test.c - test for for the module access
    Copyright (C) 2012  Adrian Remonda
                        FuDePAN
    This file is part of the reclamamem Proyect.

    Reclamamem is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Reclamamem is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Reclamamem.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * device specifics, such as ioctl numbers and the
 * major device file.
 */
#include "reclamamem.h"

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>      /* open */
#include <unistd.h>     /* exit */
#include <sys/ioctl.h>      /* ioctl */

#define DEVICE_FILE_NAME "/dev/reclamamem"

/*
 * Main - Call the ioctl functions
 */
main()
{
    int file_desc, ret_val;
    int c;
    char msg[100] = "Message passed by ioctl\n";

    file_desc = open(DEVICE_FILE_NAME, O_RDWR);
    if (file_desc < 0)
    {
        printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
        exit(-1);
    }

    char buf[100] = "";
    ret_val = read(file_desc, buf, sizeof(buf));
    if (ret_val == -1)
    {
        perror("read");
        exit(1);
    }
    else
    {
        printf("Got from device: %s\n", buf);
    }

    /* ioctl test */
    c = ioctl(file_desc, IOCTL_TO_DEFINE_1, 0);

    if (c < 0)
    {
        printf("ioctl_get_nth_byte failed\n");
        exit(-1);
    }

    printf("IOCTL 1 got: 0x%.2x\n", c);
    close(file_desc);
}
